import 'package:flutter/material.dart';
import 'package:kq_flutter_widgets/widgets/swiper/kq_roll_swipe.dart';

import '../imageBox/kq_head_image_box_item_view.dart';
import 'entity/kq_form_entity.dart';

class KqHeadImageBoxView extends StatefulWidget {
  /// 数据实体类
  final KqFormEntity entity;

  ///模认图片
  final String defaultPic;

  /// 图片添加按钮点击回调
  final Function(KqFormEntity entity, KqHeadImageBoxItemViewState state,
      VoidCallback callBack)? onAddTap;

  const KqHeadImageBoxView(
      {Key? key, required this.entity, required this.defaultPic, this.onAddTap})
      : super(key: key);

  @override
  State<KqHeadImageBoxView> createState() => _KqHeadImageBoxViewState();
}

class _KqHeadImageBoxViewState extends State<KqHeadImageBoxView> {
  @override
  Widget build(BuildContext context) {
    return widget.entity.editable
        ? KqHeadImageBoxItemView(
            entity: widget.entity,
            defaultPic: widget.defaultPic,
            onAddTap: (entity, state, callBack) {
              if (widget.onAddTap != null) {
                widget.onAddTap!.call(widget.entity, state, callBack);
              }
            },
          )
        : KqRollSwipe(
            urls: widget.entity.imageUrls ?? [],
            defaultPic: widget.defaultPic,
            tagEnable: true,
          );
  }
}
